const app = getApp();
const weixinId = app.globalData.weixinId;
const alreadyLoggedIn = app.globalData.alreadyLoggedIn;
Page({
  data: {
    userName: '',
    weixinId: '',
    alreadyLoggedIn: alreadyLoggedIn,
  },
  login() {
    if (this.data.alreadyLoggedIn == true) {
      wx.showModal({
        title: '提示',
        content: '确定退出登录',
        complete: (res) => {
          if (res.cancel) {
          }
          if (res.confirm) {
            app.resetglobalData(); //重置用户信息
            wx.reLaunch({
              url: '/pages/setting/setting',
              complete: () => {
                wx.showModal({
                  title: '提示',
                  content: '退出登录成功',
                  showCancel: false,
                });
              },
            });
          }
        },
      });
    } else {
      wx.reLaunch({
        url: '/pages/getweixinid/getweixinid', // 你要重新加载的页面路径
        success: function () {},
        fail: function (err) {},
        complete: function () {},
      });
    }
  },
  onLoad: function (options) {
    console.log('重进');
    this.setData({
      userName: app.globalData.userInfo.nickName,
      weixinId: app.globalData.weixinId,
      alreadyLoggedIn: !!app.globalData.weixinId,
    });
    console.log(this.data.weixinId);
    console.log(this.data.alreadyLoggedIn);
  },

  onReady: function () {
    wx.setNavigationBarTitle({
      title: '设置',
    });
  },
});
